from problembase import ProblemBase
from dolfin import RectangleMesh, Expression
from math import pi,sqrt

class DrivenCircle(ProblemBase):
    'Circle (x0,y0,r) driven by constant velocity field (v1,v2).'
    def __init__(self,options):
        ProblemBase.__init__(self,options)

        self.LL = (-2.,-2.)                              # lower left
        self.UR = (6.,2.)                                # upper right; points for rectangle defition

        self.domain = RectangleMesh(self.LL[0],self.LL[1],self.UR[0],self.UR[1],2*self.N,1*self.N)
        
        self.radius = 1                     # radius, center coordinates 
        self.x0 = 0
        self.y0 = 0

        self.vStrings = ('1.','0.')                  # string for velocity compononets    
        self.vIsTimeDependent = False               
        self.hasExactSolution = True                # exact is defined
        self.phi_ = self.exact_solution() 
        self.T = 4        
        self.activeCols = [0,1,2,3,4,5,6,7]
        ProblemBase.register_variables(self)
        self.ibcExpr = self.exact_solution
        self.L = 2*pi*radius

    def exact_volume(self):
        '''Return problem specific exact volume.'''
        return pi*self.radius**2
        
    def exact_solution(self,t=0):
        '''Return problem specific exact solution at time t.'''
        r = self.radius
        x0 = self.x0
        y0 = self.y0
        return Expression('sqrt(\
                              (x[0]-x0-(%(vX)s)*t)*(x[0]-x0-(%(vX)s)*t)\
                             +(x[1]-y0-(%(vY)s)*t)*(x[1]-y0-(%(vY)s)*t)\
                               )-r' % {'vX' : self.vStrings[0],'vY' : self.vStrings[1]},r=r,x0=x0,y0=y0,t=t)








